package com.jjlin.chapter_8;

import java.util.*;
public class CD150{
    public static void rotate(int[][] nums){
        int tR = 0, tC = 0;
        int dR = nums.length - 1, dC = nums[0].length - 1;
        while(tR < dR){
            rotateEdge(nums, tR++, tC++, dR--, dC--);
        }
    }

    //顺时针90度旋转左上角为(a,b)、右下角为(c,d)的正方形
    public static void rotateEdge(int[][] nums, int tR, int tC, int dR, int dC){
        int times = dC - tC;
        for(int i = 0; i < times; i++){
            int tmp = nums[tR][tC + i];
            nums[tR][tC + i] = nums[dR - i][tC];
            nums[dR - i][tC] = nums[dR][dC - i];
            nums[dR][dC - i] = nums[tR + i][dC];
            nums[tR + i][dC] = tmp;
        }
    }

    //打印数组
    public static void printArray(int[][] nums){
        int rows = nums.length;
        int cols = nums[0].length;
        int i, j;
        for(i = 0; i < rows; i++){
            for(j = 0; j < cols - 1; j++)
                System.out.print(nums[i][j] + " ");
            System.out.println(nums[i][j]);
        }
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int row = sc.nextInt();
        int[][] nums = new int[row][row];
        for(int i = 0; i < row; i++)
            for(int j = 0; j < row; j++)
                nums[i][j] = sc.nextInt();
        rotate(nums);
        printArray(nums);
    }
}